package com.bdqn.zhang.controller;

import com.bdqn.zhang.pojo.User;
import com.bdqn.zhang.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

/**
 * @Author: tao
 * @Description: talk is cheap,show me the code!
 * @Date: create in 2020/9/24 15:13
 */
@Controller
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserService userService;

    /*@RequestMapping("/login")
    *//*RequestParam  只写名字 代表参数是必须传的 如果不传 会抛400异常*//*
    public String login(@RequestParam(required = false,value = "username")String username,
                        @RequestParam(required = false,value = "password")String password){

        return "login";
    }*/
    @RequestMapping("/toLogin")
    public String toLogin(){
        return "login";
    }


    @RequestMapping("/login")
    /*RequestParam  只写名字 代表参数是必须传的 如果不传 会抛400*/
    public String login2(User user, Model model){
        User u =  userService.login(user);
        if (u != null) {
            model.addAttribute("user",u);
            /*逻辑视图名*/
            return "index";
        } else {
            return "login";
        }

    }


}
